package com.blq.developtools.widget.floathelper;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;

import com.blq.developtools.R;
import com.blq.developtools.bean.LayoutInspectorBean;
import com.blq.developtools.observerpattern.observable.LayoutViewerObservable;
import com.blq.developtools.service.DevelopToolsService;
import com.blq.developtools.view.viewholder.LayoutInspectorViewHolder;

/**
 * <pre>
 * ****************************************************************
 * 文件名称:LayoutInspectorWindowHelper.java
 * 作 者:SSNB
 * 创建时间:2024/5/22
 * 文件描述:
 * 注意事项:
 * 版权声明:Copyright (C) 2015-2025 杭州中焯信息技术股份有限公司
 * 修改历史:2024/5/22 1.00 初始版本
 * ****************************************************************
 * </pre>
 */
public class LayoutInspectorWindowHelper extends FloatWindowHelper {
    private LayoutInspectorViewHolder viewHolder;

    public LayoutInspectorWindowHelper(Context context) {
        super(context);
        viewHolder = new LayoutInspectorViewHolder(context);
        setLayoutView(viewHolder.getRootView());
        initView();
    }

    public LayoutInspectorWindowHelper(Context context, int layoutID) {
        super(context, layoutID);
        viewHolder = new LayoutInspectorViewHolder(getLayoutView());
        initView();
    }

    public LayoutInspectorWindowHelper(Context context, View layoutView) {
        super(context, layoutView);
        viewHolder = new LayoutInspectorViewHolder(layoutView);
        initView();
    }

    private void initView() {
        LayoutInspectorBean bean = new LayoutInspectorBean();
        bean.setPackageName("");
        bean.setClassName("");
        viewHolder.bindData(bean);
        viewHolder.setActionClickListener(new LayoutInspectorViewHolder.OnActionClickListener() {
            @Override
            public void onCloseClick() {
                LayoutViewerObservable.getInstance().onLayoutInspectorStatus(false);
                close();
            }

            @Override
            public void onLayoutScanClick() {
                DevelopToolsService.setScanLayout(getContext(), true);
            }

            @Override
            public void onAppInfoClick() {
                setMode(!viewHolder.getBindData().isSmall());
            }
        });
    }

    public void updateView() {
        viewHolder.bindData(viewHolder.getBindData());
    }

    public void updateInfo(String appName, String packageName, String className) {
        LayoutInspectorBean bean = viewHolder.getBindData();
        bean.setAppName(appName);
        bean.setPackageName(packageName);
        bean.setClassName(className);
        viewHolder.bindData(bean);
    }

    public void setMode(boolean isSmall) {
        LayoutInspectorBean bean = viewHolder.getBindData();
        bean.setSmall(isSmall);
        viewHolder.bindData(bean);
    }
}
